//
//  Router.h
//  OneStoreFramework
//
//  Created by Aimy on 14-6-23.
//  Copyright (c) 2014年 OneStore. All rights reserved.
//

#import <UIKit/UIKit.h>
#import "RouterVO.h"

#import <BaseCode/BaseAppDelegate.h>

NS_ASSUME_NONNULL_BEGIN


typedef void(^RouterWillExecuteBlock)(UIViewController *vc);

#define RouterIsNeedLoginFirstKey @"isNeedLoginFirst"//需要注册一个 key 为 isNeedLoginFirst 返回一个bool 值的函数 用来判断当前登录状态 

@class RouterVO;

@interface Router : NSObject

+ (instancetype)sharedInstance;

@property (nullable, nonatomic, strong, readonly) BaseAppDelegate *appDelegate;//[UIApplication sharedApplication].delegate
@property (nullable, nonatomic, strong, readonly) UITabBarController *rootTBC;
@property (nullable, nonatomic, strong, readonly) UINavigationController *currentNC;

@property (atomic, strong, readonly) NSMutableDictionary *routeMapping;
@property (atomic, strong, readonly) NSMutableDictionary *nativeCallMapping;

@property (nonatomic, strong, readonly) NSString *routeScheme;
@property (nonatomic, strong, readonly) NSString *nativeCallScheme;
@property (nonatomic, strong, readonly) NSString *appScheme;

- (void)updateRouteScheme:(NSString * _Nonnull)routeScheme
         nativeCallScheme:(NSString * _Nonnull)nativeCallScheme
                appScheme:(NSString * _Nonnull)appScheme;

- (RouterVO *)getRouterVOWithKey:(NSString *)key;

- (NativeCallVO *)getNativeCallVOWithKey:(NSString *)key;

- (void)presentPC:(UIViewController *)pc;

@end

@interface Router (registery)

- (void)registerRouterVO:(RouterVO *)aVO withKey:(NSString *)key;

- (void)registerNativeCallVO:(NativeCallVO *)aVO withKey:(NSString *)key;

@end

#pragma mark - route

@interface Router (route)

#pragma mark - route with key

- (BOOL)routeWithKey:(NSString *)key;

- (BOOL)routeWithKey:(NSString *)key
              params:(nullable NSDictionary * )params;

- (BOOL)routeWithKey:(NSString *)key
              params:(nullable NSDictionary * )params
            callback:(nullable NativeCallVOBlock)callback;

#pragma mark - route with URL string

- (BOOL)routeWithURLString:(NSString *)aURLString;

- (BOOL)routeWithURLString:(NSString *)aURLString
                    params:(nullable NSDictionary *)params;

- (BOOL)routeWithURLString:(NSString *)aURLString
                  callback:(nullable NativeCallVOBlock)callback;

- (BOOL)routeWithURLString:(NSString *)aURLString
                    params:(nullable NSDictionary *)params
                  callback:(nullable NativeCallVOBlock)callback;

#pragma mark - route with URL

- (BOOL)routeWithURL:(NSURL *)aURL;

- (BOOL)routeWithURL:(NSURL *)aURL
            callback:(nullable NativeCallVOBlock)callback;

#pragma mark - route with

- (nullable UIViewController *)viewControllerWithKey:(NSString *)key
                                              params:(nullable NSDictionary *)params
                                            callback:(nullable NativeCallVOBlock)callback;

- (nullable UIViewController *)viewControllerWithURL:(NSURL *)url
                                              params:(nullable NSDictionary *)params
                                            callback:(nullable NativeCallVOBlock)callback;

@end

#pragma mark - Convenience Route

@interface Router (Convenience)

- (void)routeToLogin;// 调起登录
- (void)routeToHomePage;// 进入首页
- (void)routeBack;
@end

#pragma mark - native call

@interface Router (NativeCall)

- (id)nativeCallWithKey:(NSString *)key;

- (id)nativeCallWithKey:(NSString *)key
                   params:(nullable NSDictionary *)params;

- (id)nativeCallWithKey:(NSString *)key
                   params:(nullable NSDictionary *)params
                 callback:(nullable NativeCallVOBlock)callback;

@end

@interface Router (URL)

- (NSString *)urlStringForRouteKey:(NSString *)key andParams:(nullable NSDictionary *)params;

- (NSDictionary *)getBodyParamsFromJsonString:(nullable NSString *)aJsonString;

@end


NS_ASSUME_NONNULL_END
